package games

import (
	"errors"
	"wzgames/internal/model/statement"
)

// IMarkerService 游戏每局记录
type IMarkerService interface {
	InitServerSeed(string, string)
	ServerSeed() string
	NextServerSeed256() string
	RefreshSeed(nextServerSeed string)
	Balance() float64
	BalanceStr() string
	SetBalance(balance string, wv int64)
	IfBalanceEnough(betAmt string) bool
	BalanceInc(amt string) int16
	BalanceDec(amt string) int16
	InPlay() bool
	SetPlay(b bool)
}

type BetDelay struct {
	Tb      *GameTable
	BetObj  *statement.PlayBet
	BetChip interface{}
	Result  interface{}
}

type AutoCashOutCheckPoint struct {
	Tb       *GameTable
	BetIdx   string
	RoundId  int64
	Multi    float64
	MaxMulti float64
}

type MarkerFn func() IMarkerService

var (
	myMarkers = make(map[int32]MarkerFn)
)

func RegisterMarker(gameId int32, fn MarkerFn) {
	if fn == nil {
		panic("[Games]: Marker register provider is nil")
	}
	if _, dup := myMarkers[gameId]; !dup {
		myMarkers[gameId] = fn
	}
}

func NewMarker(gameId int32) (IMarkerService, error) {
	if ge, ok := myMarkers[gameId]; ok {
		return ge(), nil
	}

	return nil, errors.New("unknown marker instant id")
}
